package com.yupi.aicodehelper.ai.dto;

public class PerformanceMetrics {
    private final long startTime;
    private long firstTokenTime = -1;
    private long lastTokenTime = -1;
    private int tokenCount = 0;

    public PerformanceMetrics() {
        this.startTime = System.currentTimeMillis();
    }

    public void recordToken() {
        long now = System.currentTimeMillis();
        if (firstTokenTime == -1) {
            firstTokenTime = now - startTime; // 首 token 延迟
        }
        lastTokenTime = now;
        tokenCount++;
    }

    public long getFirstTokenLatency() {
        return firstTokenTime;
    }

    public double getAverageTokenLatency() {
        if (tokenCount <= 1) return 0;
        return (lastTokenTime - (startTime + firstTokenTime)) / (double) (tokenCount - 1);
    }

    public int getTokenCount() {
        return tokenCount;
    }
}
